package com.ruoyi.csdn.controller;

import java.util.List;

import com.ruoyi.common.utils.aes.AESEncryptor;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.csdn.domain.CsdnUser;
import com.ruoyi.csdn.service.ICsdnUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CSDN账户管理Controller
 * 
 * @author ruoyi
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/csdn/user")
public class CsdnUserController extends BaseController
{
    @Autowired
    private ICsdnUserService csdnUserService;

    @Autowired
    private AESEncryptor aesEncryptor;

    /**
     * 查询CSDN账户管理列表
     */
    @PreAuthorize("@ss.hasPermi('csdn:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsdnUser csdnUser)
    {
        startPage();
        List<CsdnUser> list = csdnUserService.selectCsdnUserList(csdnUser);
        return getDataTable(list);
    }

    /**
     * 导出CSDN账户管理列表
     */
    @PreAuthorize("@ss.hasPermi('csdn:user:export')")
    @Log(title = "CSDN账户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsdnUser csdnUser)
    {
        List<CsdnUser> list = csdnUserService.selectCsdnUserList(csdnUser);
        ExcelUtil<CsdnUser> util = new ExcelUtil<CsdnUser>(CsdnUser.class);
        util.exportExcel(response, list, "CSDN账户管理数据");
    }

    /**
     * 获取CSDN账户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('csdn:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(csdnUserService.selectCsdnUserById(id));
    }

    /**
     * 新增CSDN账户管理
     */
    @PreAuthorize("@ss.hasPermi('csdn:user:add')")
    @Log(title = "CSDN账户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsdnUser csdnUser)
    {
        csdnUser.setCsdnPassword(aesEncryptor.encrypt(csdnUser.getCsdnPassword()));
        return toAjax(csdnUserService.insertCsdnUser(csdnUser));
    }

    /**
     * 修改CSDN账户管理
     */
    @PreAuthorize("@ss.hasPermi('csdn:user:edit')")
    @Log(title = "CSDN账户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsdnUser csdnUser)
    {
        return toAjax(csdnUserService.updateCsdnUser(csdnUser));
    }

    /**
     * 删除CSDN账户管理
     */
    @PreAuthorize("@ss.hasPermi('csdn:user:remove')")
    @Log(title = "CSDN账户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(csdnUserService.deleteCsdnUserByIds(ids));
    }
}
